package com.msb.servicedriveuser.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.msb.commons.dto.DriverUserWorkStatus;
import com.msb.commons.response.ResponseResult;
import com.msb.servicedriveuser.mapper.DriverUserWorkStatusMapper;
import com.msb.servicedriveuser.service.DriverUserWorkStatusService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chshh
 * @since 2022-10-25
 */
@Service
public class DriverUserWorkStatusServiceImpl extends ServiceImpl<DriverUserWorkStatusMapper, DriverUserWorkStatus> implements DriverUserWorkStatusService {
    @Resource
    private DriverUserWorkStatusMapper driverUserWorkStatusMapper;

    @Override
    public ResponseResult changeWorkStatus(Long driverId, Integer workStatus) {
        QueryWrapper<DriverUserWorkStatus> wrapper = new QueryWrapper<>();
        wrapper.eq("driver_id",driverId);
        List<DriverUserWorkStatus> driverUserWorkStatuses = driverUserWorkStatusMapper.selectList(wrapper);
        DriverUserWorkStatus driverUserWorkStatus = driverUserWorkStatuses.get(0);

        driverUserWorkStatus.setWorkStatus(workStatus);
        driverUserWorkStatus.setGmtCreate(LocalDateTime.now());
        driverUserWorkStatusMapper.updateById(driverUserWorkStatus);
        return ResponseResult.success();
    }
}
